package com.example.moblie203zlw_databases11_05.slice;
import com.example.moblie203zlw_databases11_05.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;
import ohos.app.Context;
import java.util.List;

public class item_provider extends BaseItemProvider {
    List<itme> list ;
    Context context;

    public item_provider(List<itme> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        Component parse;
        itme itme=list.get(i);
        if (component!=null){
            parse=component;
        }else {
            parse= LayoutScatter.getInstance(context).parse(ResourceTable.Layout_my_item,null,false);
        }
        Text item_name = (Text) parse.findComponentById(ResourceTable.Id_item_name);
        Image image= (Image) parse.findComponentById(ResourceTable.Id_image);
        if (itme.sex.equals("男")){
            image.setImageAndDecodeBounds(ResourceTable.Media_boy);
        }
        if (itme.sex.equals("女")){
            image.setImageAndDecodeBounds(ResourceTable.Media_lady);
        }
        item_name.setText("姓名:"+itme.name);
        item_name.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent=new Intent();
                Operation operation=new Intent.OperationBuilder()
                        .withBundleName("com.example.moblie203zlw_databases11_05")
                        .withAbilityName("com.example.moblie203zlw_databases11_05.my_update")
                        .build();
                intent.setParam("name", itme.name);
                intent.setParam("sex", itme.sex);
                intent.setParam("phone",itme.phone);
                intent.setOperation(operation);
                context.startAbility(intent,1);
            }
        });
        return parse;
    }
}
